import { PersonalSet } from "./features/PersonalSet";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GTabBar } from "../../../../com/mui/controls/GTabBar";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { FriendInimateList } from "./friendandinimate/FriendInimateList";
import { FriendsList } from "./FriendsList";
import { GButton } from "../../../../com/mui/controls/GButton";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GScrollPane } from "../../../../com/mui/controls/GScrollPane";
import { FriendsPanel } from "./FriendsPanel";
//class FriendsPart
    
    export  class FriendsPart /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._chatSet = new PersonalSet();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.createChildren();
            this.addListeners();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._Bg2 = ResouceConst.getScaleBitmap("WindowCenterB");
            this._Bg2.x = 0;
            this._Bg2.y = 22;
            this._Bg2.setSize(206, 282);
            this.addChild(this._Bg2);
            this._tabBar = new GTabBar();
            this._tabBar.x = 2;
            this._tabBar.y = 0;
            this._tabBar.buttonWidth = 49;
            this._tabBar.horizontalGap = 1;
            this._tabBar.buttonFilters = [FilterConst.glowFilter];
            this._tabBar.dataProvider = this._typeData;
            this.addChild(this._tabBar);
            this._blessAll = ObjCreate.createGButton(Language.getString(40406), 125, 25, 70, 22, this);
            this._friendList = new FriendInimateList();
            this._friendList.x = 6;
            this._friendList.y = 28;
            this.addChild(this._friendList);
            this._enemyList = this.createList(FriendsList.enemy);
            this._blackList = this.createList(FriendsList.blackList);
            this._recentList = this.createList(FriendsList.recent);
            this._recentList.friendTileList.verticalGap = 3;
            this._friendList.visible = true;
            this._btnSelfSet = new GButton();
            this._btnSelfSet.width = 70;
            this._btnSelfSet.height = 26;
            this._btnSelfSet.x = 9;
            this._btnSelfSet.y = 310;
            this._btnSelfSet.label = Language.getString(40377);
            this._btnSelfSet.textField.filters = [FilterConst.glowFilter];
            this._btnSelfSet.styleName = "ButtonLarge";
            this.addChild(this._btnSelfSet);
            this._btnBulkDelete = new GButton();
            this._btnBulkDelete.width = 70;
            this._btnBulkDelete.height = 26;
            this._btnBulkDelete.x = 128;
            this._btnBulkDelete.label = Language.getString(40398);
            this._btnBulkDelete.y = 310;
            this._btnBulkDelete.textField.filters = [FilterConst.glowFilter];
            this._btnBulkDelete.styleName = "ButtonLarge";
            this.addChild(this._btnBulkDelete);
            return;
        }

        /* internal  */createList(arg1: string): FriendsList
        {
            var loc1=new FriendsList(arg1);
            loc1.x = 6;
            loc1.y = 28;
            loc1.visible = false;
            this.addChild(loc1);
            return loc1;
        }

        /* internal  */addListeners(): void
        {
            this._tabBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.tabBarChangeHandler);
            this._btnSelfSet.addEventListener(flash.events.MouseEvent.CLICK, this.showSetHandler);
            this._btnBulkDelete.addEventListener(flash.events.MouseEvent.CLICK, this.bulkDeleteHandler);
            this._blessAll.addEventListener(flash.events.MouseEvent.CLICK, this.onBlessAllClickHandler);
            return;
        }

        /* internal  */showSetHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._chatSet.show();
            return;
        }

        /* internal  */bulkDeleteHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (Cache.instance.friend.getFriendList().length > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.FriendShowBulkDeleteWindow));
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(40399));
            }
            return;
        }

        /* internal  */onBlessAllClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc4=null;
            var loc1=Cache.instance.friend.getFriendList();
            var loc2=new Array<any>();
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                if (!(loc4 = loc1[loc3]).isCornucopiaed() && loc4.friendPlayerInfo.online) 
                {
                    loc2.push(loc4.friendPlayerInfo.playerId);
                }
                ++loc3;
            }
            if (loc2.length != 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CornucopiaBlessAll, loc2));
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(40407));
            }
            return;
        }

        /* internal  */tabBarChangeHandler(arg1: MuiEvent): void
        {
            this._friendList.visible = false;
            this._enemyList.visible = false;
            this._blackList.visible = false;
            this._recentList.visible = false;
            var loc1=this._tabBar.selectedIndex;
            switch (loc1) 
            {
                case 0:
                {
                    this._isInFriendTab = true;
                    this._friendList.visible = true;
                    break;
                }
                case 1:
                {
                    this._isInFriendTab = false;
                    this._enemyList.visible = true;
                    break;
                }
                case 2:
                {
                    this._isInFriendTab = false;
                    this._blackList.visible = true;
                    break;
                }
                case 3:
                {
                    this._isInFriendTab = false;
                    this._recentList.visible = true;
                    break;
                }
                default:
                {
                    this._friendList.visible = true;
                }
            }
            this.updateBlessAllBtnVisible();
            return;
        }

        public set isHaveCanBlessFriend(arg1: Boolean)
        {
            this._isHaveCanBlessFriend = arg1;
            this.updateBlessAllBtnVisible();
            return;
        }

        /* internal  */updateBlessAllBtnVisible(): void
        {
            this._blessAll.visible = this._isHaveCanBlessFriend && this._isInFriendTab;
            return;
        }

        public get friendList(): FriendInimateList
        {
            return this._friendList;
        }

        public get enemyList(): FriendsList
        {
            return this._enemyList;
        }

        public get blackList(): FriendsList
        {
            return this._blackList;
        }

        public get recentList(): FriendsList
        {
            return this._recentList;
        }

        /* internal */ /* const */_typeData: Array<any>=[{"name": FriendsList.friend, "label": Language.getString(40373)}, {"name": FriendsList.enemy, "label": Language.getString(40374)}, {"name": FriendsList.blackList, "label": Language.getString(40375)}, {"name": FriendsList.recent, "label": Language.getString(40376)}];

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_Bg1: ScaleBitmap;

        /* internal */ /* var */_Bg2: ScaleBitmap;

        /* internal */ /* var */_blessAll: GButton;

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_friendList: FriendInimateList;

        /* internal */ /* var */_enemyList: FriendsList;

        /* internal */ /* var */_blackList: FriendsList;

        /* internal */ /* var */_recentList: FriendsList;

        /* internal */ /* var */_currnetList: FriendsList;

        /* internal */ /* var */_FriendsPanel: FriendsPanel;

        /* internal */ /* var */_btnSelfSet: GButton;

        /* internal */ /* var */_btnBulkDelete: GButton;

        /* internal */ /* var */_chatSet: PersonalSet;

        /* internal */ /* var */_isHaveCanBlessFriend: Boolean=false;

        /* internal */ /* var */_isInFriendTab: Boolean=true;
    }
